package com.mf.service.impl;

import com.mf.entity.RecommendCode;
import com.mf.mapper.code.Code000Mapper;

import com.mf.vo.MACD.MACDVo;
import com.mf.service.IHomeService;
import com.mf.utils.MACDUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lmf
 * @Create: 2024/5/1 10:31
 * Description:
 */
@Service
public class HomeServiceImpl implements IHomeService {
    @Resource
    private Code000Mapper code000Mapper;

    /**
     * 获取macd
     */
    @Override
    public MACDVo findMacd(List<RecommendCode> codeList) {
        // 计算MACD（短期12天，长期26天，信号9天）
        int shortPeriod = 12;
        int longPeriod = 26;
        int signalPeriod = 9;
        return MACDUtils.calculateMacd(codeList, shortPeriod, longPeriod, signalPeriod);
    }

    /**
     * 获取获取k线图
     */
    @Override
    public double[][] getKLine(List<RecommendCode> codeList) {
        // 计算需要多少行
        int rowCount = codeList.size();
        // 创建一个二维数组，每行有4个元素
        double[][] k = new double[rowCount][4];

        for (int i = 0; i < rowCount; i++) {
            RecommendCode code = codeList.get(i);
            double[] v = new double[4];
            v[0] = code.getO();
            v[1] = code.getC();
            v[2] = code.getL();
            v[3] = code.getH();

            // 将每行的数据赋值给二维数组
            System.arraycopy(v, 0, k[i], 0, 4);
        }

        return k;
    }



}
